#!/usr/bin/env python

import MySQLdb

def connect(ip) :
	conn = MySQLdb.connect(ip, 'gamevil', 'vlwlrpaqlf', 'pz_user')
	csr  = conn.cursor()
	return (conn, csr)

connMap = {}
connMap["100"] = connect('172.16.1.181')
connMap["101"] = connect('172.16.1.182')
connMap["102"] = connect('172.16.2.31')
connMap["103"] = connect('172.16.2.32')
connMap["104"] = connect('172.16.2.33')
connMap["105"] = connect('172.16.2.34')

sql = """
	UPDATE info_item SET status = 3
	WHERE user_seq = %d
	  AND reg_date >= 1391958000
	  AND reg_date <= 1391966440
	  AND quality >= 2
	  AND bag_type IN (0, 1)
  """

fd = open("userinfo.txt")
for line in fd.xreadlines() :
	user_seq, shard_type, dummy = line.strip().split(",", 2)
	conn, csr = connMap.get(shard_type)
	csr.execute(sql % int(user_seq))
	conn.commit()
fd.close()


for shard_type in connMap.keys() :
	print "close... %s" % shard_type
	conn, csr = connMap.get(shard_type)
	csr.close()
	conn.close()
